﻿package com.tudou.home.newskin.containers
{
    import com.tudou.consts.*;
    import com.tudou.cookie.*;
    import com.tudou.events.*;
    import com.tudou.home.newskin.buttons.*;
    import com.tudou.home.newskin.consts.*;
    import com.tudou.home.newskin.events.*;
    import com.tudou.home.utils.*;
    import com.tudou.js.*;
    import com.tudou.skin.*;
    import com.tudou.skin.common.button.*;
    import com.tudou.skin.common.events.*;
    import com.tudou.track.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;

    public class Rate extends SelectRadioMenu implements IRate, IShowWidthHeight, ISetting
    {
        private var rateRadio:RateRadio;
        private var arrowTip:DisplayObject;
        private var rateSettingData:RateSettingData;
        private var skipSettingData:SkipSettingData;
        private var _maxRate:int;
        private var _original:Boolean;

        public function Rate(param1:int, param2:Boolean)
        {
            _maxRate = param1;
            _original = param2;
            rateRadio = new RateRadio(param1, param2);
            super(new RateButton(param1, param2), rateRadio, new Point(), new Point(0, -3));
            activeKey = RateType.P256.toString();
            selected = false;
            CenterDisptcher.getInst().addEventListener(NewSkinConsts.ARROW_TIP_EVENT, centerHlr);
            addEventListener(Event.ADDED_TO_STAGE, addToStageHlr);
            return;
        }// end function

        public function setMaxRate(param1:int, param2:Boolean) : void
        {
            return;
        }// end function

        private function centerHlr(event:CenterEvent) : void
        {
            if (event.data[0] == NewSkinConsts.ARROW_SHOW)
            {
                addArrow();
            }
            else if (event.data[0] == NewSkinConsts.ARROW_HIDE)
            {
                removeArrow();
            }
            return;
        }// end function

        public function get showWidth() : uint
        {
            return selectSkin.width;
        }// end function

        public function get showHeight() : uint
        {
            return selectSkin.height;
        }// end function

        public function setRateSetting(param1:RateSettingData) : void
        {
            rateSettingData = param1;
            return;
        }// end function

        override protected function selectHlr(event:SelectEvent) : void
        {
            selected = !event.selected;
            CenterDisptcher.getInst().dispatchEvent(new CenterEvent(NewSkinConsts.CLEAR_HAS_ORIGINAL, null));
            return;
        }// end function

        public function getRate() : int
        {
            return int(activeKey);
        }// end function

        public function setSkipSeting(param1:SkipSettingData) : void
        {
            skipSettingData = param1;
            return;
        }// end function

        public function setRate(param1:int) : void
        {
            activeKey = param1.toString();
            return;
        }// end function

        private function addArrow() : void
        {
            if (arrowTip == null)
            {
                arrowTip = new ArrowTipMC();
                arrowTip.x = 30;
                arrowTip.y = -14;
                addChild(arrowTip);
            }
            return;
        }// end function

        private function removeArrow() : void
        {
            if (arrowTip)
            {
                removeChild(arrowTip);
                arrowTip = null;
            }
            return;
        }// end function

        private function saveRateHlr(event:JSEvent) : void
        {
            var _loc_4:RateSettingData = null;
            var _loc_5:SkipSettingData = null;
            var _loc_2:* = event.data;
            var _loc_3:* = _loc_2[0];
            if (_loc_3 == "rate")
            {
                _loc_4 = new RateSettingData(_loc_2[1]);
                dispatchEvent(new SkinEvent(SkinEvent.SAVE_RATE_SETTING, _loc_4));
            }
            else if (_loc_3 == "skip")
            {
                _loc_5 = new SkipSettingData(_loc_2[1]);
                dispatchEvent(new SkinEvent(SkinEvent.SAVE_SKIP_SETTING, _loc_5));
            }
            return;
        }// end function

        override protected function radioHlr(event:RadioEvent) : void
        {
            selected = false;
            dispatchEvent(new SkinEvent(SkinEvent.SET_RATE, int(event.clickKey)));
            return;
        }// end function

        private function addToStageHlr(event:Event) : void
        {
            rateRadio.rateSetting.addEventListener(MouseEvent.CLICK, settingClickHlr);
            var _loc_2:* = JSExchanger.getInst();
            _loc_2.addEventListener("saveSettingData", saveRateHlr);
            removeEventListener(Event.ADDED_TO_STAGE, addToStageHlr);
            addEventListener(Event.REMOVED_FROM_STAGE, removeFromStageHlr);
            return;
        }// end function

        private function settingClickHlr(event:MouseEvent) : void
        {
            dispatchEvent(new SkinEvent(SkinEvent.EXIT_FULLSCREEN));
            var _loc_2:Object = {rate:rateSettingData, skip:skipSettingData};
            trace(" skipRateData " + rateSettingData);
            trace(" skipSettingData " + skipSettingData);
            JSExchanger.getInst().notifyJS("settingPanel", ["rate", _loc_2]);
            selected = false;
            dispatchEvent(new SkinEvent(SkinEvent.BUTTON_LOG, SkinButtonCode.SETTING));
            return;
        }// end function

        private function removeFromStageHlr(event:Event) : void
        {
            removeEventListener(Event.REMOVED_FROM_STAGE, removeFromStageHlr);
            rateRadio.rateSetting.removeEventListener(MouseEvent.CLICK, settingClickHlr);
            var _loc_2:* = JSExchanger.getInst();
            _loc_2.removeEventListener("saveSettingData", saveRateHlr);
            return;
        }// end function

    }
}
